﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using ZoneFiveSoftware.Common.Data.Measurement;
using ZoneFiveSoftware.Common.Visuals;
using STCommon.Controller;
using STCommon.Data;
using DistributionPlugin.Data;

namespace DistributionPlugin.View
{
    public class DistributionLabelProvider : TreeList.ILabelProvider
    {
        public DistributionLabelProvider(ILabelUnitProvider provider)
        {
            Debug.Assert(provider != null);

            m_Provider = provider;
        }

#region ILabelProvider Members

        public System.Drawing.Image GetImage(object element, TreeList.Column column)
        {
            return null;
        }

        public string GetText(object element, TreeList.Column column)
        {
            if (element is DistributionZoneInfo)
            {
                DistributionZoneInfo zoneInfo = element as DistributionZoneInfo;

                switch (column.Id)
                {
                    case "Range":
                    {
                        return zoneInfo.GetRangeLabel(m_Provider);
                    }
                    case "TimePercent":
                    {
                        return String.Format("{0:0.##%}", zoneInfo.TimePercent);
                    }
                    case "TotalTime":
                    {
                        return zoneInfo.ZoneTime.ToString();
                    }
                    case "DistancePercent":
                    {
                        return String.Format("{0:0.##%}", zoneInfo.DistancePercent);
                    }
                    case "TotalDistance":
                    {
                        Length.Units distanceUnit = m_Provider.DistanceUnit;

                        return String.Format("{0:0.##} {1}",
                                             Length.Convert(zoneInfo.ZoneDistanceMeters, Length.Units.Meter, distanceUnit),
                                             Length.LabelAbbr(distanceUnit));
                    }
                }
            }

            return String.Empty;
        }

#endregion

        private ILabelUnitProvider m_Provider = null;
    }
}
